package negModel;

import negModelExcep.eParteNoFunciona;
import org.w3c.dom.Document;
import org.w3c.dom.Element;


public class Carroceria extends ParteAerodinamica{

	private int color;
	private double altoFrente;
	private double altoCabina;
	private double ancho;
	private double largo;
	
	public Carroceria (int vidaUtil, double peso,float aporteVelMax,String detalle,AlgoPesos precio,boolean removible,int aerodinamia,int color,double largo, double ancho, double altoF,double altoC){
		this.setMaxVU(vidaUtil);
		this.arreglar();
		this.setPeso(peso);
		this.setAportevmax(aporteVelMax);
		this.setDetalle(detalle);
		this.setPrecio(precio);
		this.setRemovible(removible);
		this.setAerodinamia(aerodinamia);
		
		this.ancho=ancho;
		this.largo=largo;
		this.color=color;
		this.altoFrente=altoF;
		this.altoCabina=altoC;
	}
	
	public Carroceria (Element xmlElement) {
		this.setMaxVU(Integer.parseInt(xmlElement.getAttribute("maxVU")));
		this.setVidaUtil(Integer.parseInt(xmlElement.getAttribute("vidaUtil")));
		this.setPeso(Double.parseDouble(xmlElement.getAttribute("peso")));
		this.setAportevmax(Float.parseFloat(xmlElement.getAttribute("aportevmax")));
		this.setDetalle(xmlElement.getAttribute("detalle"));
		this.setPrecio(new AlgoPesos(Double.parseDouble(xmlElement.getAttribute("precio"))));
		this.setRemovible(Boolean.parseBoolean(xmlElement.getAttribute("removible")));
		this.setAerodinamia(Integer.parseInt(xmlElement.getAttribute("aerodinamia")));
		
		this.color=Integer.parseInt(xmlElement.getAttribute("color"));
		this.altoFrente=Double.parseDouble (xmlElement.getAttribute("altoFrente"));
		this.altoCabina=Double.parseDouble (xmlElement.getAttribute("altoCabina"));
		this.ancho=Double.parseDouble (xmlElement.getAttribute("ancho"));
		this.largo=Double.parseDouble (xmlElement.getAttribute("largo"));
		
	}
	
	public Element toXml(Document doc) {
		Element xmlElement = doc.createElement("parte");
		xmlElement.setAttribute("Clase","carroceria");
		
		xmlElement.setAttribute("maxVU", ""+ this.getMaxVU());
		xmlElement.setAttribute("vidaUtil", ""+this.getVidaUtil());
		xmlElement.setAttribute("peso", ""+this.getPeso());
		xmlElement.setAttribute("aportevmax", ""+ this.aportevmax());
		xmlElement.setAttribute("detalle", this.getDetalle());
		xmlElement.setAttribute("precio", ""+(this.getPrecio()).getMonto());
		xmlElement.setAttribute("removible", ""+this.esRemovible());
		xmlElement.setAttribute("aerodinamia", ""+this.getAerodinamia());
		
		xmlElement.setAttribute("color", ""+this.color);
		xmlElement.setAttribute("altoFrente", ""+this.altoFrente);
		xmlElement.setAttribute("altoCabina", ""+this.altoCabina);
		xmlElement.setAttribute("ancho", ""+this.ancho);
		xmlElement.setAttribute("largo", ""+this.largo);
				
		return xmlElement;
	}
	
	public double getLargo() {
		return largo;
	}
	public double getAltoCabina() {
		return altoCabina;
	}
	public double getAncho() {
		return ancho;
	}
	public int getColor() {
		return color;
	}
	public double getAltoFrente() {
		return altoFrente;
	}
	
	public double funcionar () throws eParteNoFunciona{
		this.gastar();
		double coef=100/((this.largo*this.ancho)*(this.altoCabina-this.altoFrente));
		if (coef<=0) return 0; 
		else
			return coef;
	}

		
}
